//
//  YLayout.m
//  CodeForCollection
//
//  Created by 李明明 on 15/12/17.
//  Copyright © 2015年 李明明. All rights reserved.
//

#import "YLayout.h"
@implementation YLayout {
    
    NSInteger count;
}

- (void)prepareLayout
{
    [super prepareLayout];
    count = [self.collectionView numberOfItemsInSection:0];
    
}

- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSMutableArray *array = [@[] mutableCopy];
    for (int i = 0 ; i < count; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *attri = [self layoutAttributesForItemAtIndexPath:indexPath];
        [array addObject:attri];
    }
    return array;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewLayoutAttributes *attri = [UICollectionViewLayoutAttributes   layoutAttributesForCellWithIndexPath:indexPath];
    attri.frame = [self obtainRect:indexPath.item];
    return attri;
}
- (CGRect)obtainRect:(NSInteger)index {
    NSInteger number = index / 9 * 360;
    index = index % 9;
    switch (index) {
        case 0:return CGRectMake(0, 0 + number, 100, 75);break;
        case 1: return CGRectMake(130, 20 + number, 120, 86);break;
        case 2: return CGRectMake(10, 75 + number, 120, 88);break;
        case 3: return CGRectMake(170, 106 + number, 120, 90);break;
        case 4: return CGRectMake(90, 163 + number, 80, 60);break;
        case 5: return CGRectMake(170, 196 + number, 100, 70);break;
        case 6: return CGRectMake(30, 223 + number, 100, 75);break;
        case 7: return CGRectMake(130, 265 + number, 155, 110);break;
        default:
        case 8: return CGRectMake(50, 297 + number, 80, 60);
            break;
    }
}

@end
